package edu.ensmp.ckEditor.gui;

import javax.swing.JButton;
import javax.swing.JColorChooser;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.JTextArea;

import net.miginfocom.swing.MigLayout;
import edu.ensmp.ckEditor.ckModel.CKModel;
import edu.ensmp.ckEditor.control.ButtonListener;
import edu.ensmp.ckEditor.control.TabListener;
import edu.ensmp.ckEditor.util.Constants;
import edu.ensmp.ckEditor.util.UiConstants;

public class TopTabbedPane extends JTabbedPane{

	static final long serialVersionUID = 12345;
	
	private CKModel _model;
	private EditorFrame _frame;
	
	private JPanel createPanel;
	private JPanel editPanel;
	private JPanel translatePanel;
	private JTextArea conceptField;
	private JButton saveChangeButton;
	
	public JButton getSaveChangeButton() {
		return saveChangeButton;
	}

	public TopTabbedPane(CKModel model, EditorFrame frame) {
		
		_model = model;
		_frame = frame;
		createPanel = createPanel();
		editPanel = editPanel();
		translatePanel = translatePanel();
		
		this.addTab("Create", createPanel);
		this.addTab("Edit", editPanel);
		this.addTab("Translate", translatePanel);

		this.addChangeListener(new TabListener());

	}
	
	private JPanel createPanel(){
		JPanel panel;
		panel = new JPanel();
		panel.setLayout(new MigLayout("fillx"));
		panel.setOpaque(false);
		
		JTextArea helpText = new JTextArea(Constants.HELP_TEXT);
		helpText.setEditable(false);
		helpText.setOpaque(false);		
		panel.add(helpText, "center");
		
		return panel;
		
	}
	
	private JPanel editPanel(){
		JPanel panel;
		panel = new JPanel();
		panel.setLayout(new MigLayout("fill", "[90%][10%]"));
		panel.setOpaque(false);
		
		conceptField = new JTextArea(UiConstants.DEFAULT_EDIT_TEXTFIELD_STRING);
		panel.add(conceptField, "growx, growy");
		
		JButton colorChooser = new JButton("Change Color");
		colorChooser.addActionListener(new ButtonListener(_model, _frame));
		panel.add(colorChooser, "growx, wrap");
		
		saveChangeButton = new JButton("Save Changes");
		saveChangeButton.addActionListener(new ButtonListener(_model, _frame));
		panel.add(saveChangeButton, "cell 1 1, right");
		
		return panel;
	}
	
	private JPanel translatePanel(){
		JPanel panel;
		panel = new JPanel();
		panel.setLayout(new MigLayout());
		panel.setOpaque(false);
		
		return panel;
	}
	
	public void setConceptField(String mot){
		this.conceptField.setText(mot);
		
	}
	public String getConceptField(){
		return this.conceptField.getText();
	}

}
